//sandbox size : 970x600
PImage ripSandbox(boolean drawOutline)
{
  background(0);
  if (drawOutline)
  {
    image(levelOutline,levelOutlinePos[0],levelOutlinePos[1]);
  }
  globalShapeContainer.doDraw();
  PImage sandbox = get(levelOutlinePos[0],levelOutlinePos[1],970,600);
  sandbox.save("saved_images/ripped.png");
  return sandbox;
}

boolean sameImage(PImage imageA, PImage imageB)
{
  imageA.loadPixels();
  imageB.loadPixels();
  
  PImage diff = createImage(970,600,RGB);
  diff.loadPixels();
  
  int offPixels = 0;
  int extraPixels = 0;
  if (difficulty == 0 && userLevel[difficulty] == 1) { extraPixels = 17386/*11678*/; }
  if (difficulty == 0 && userLevel[difficulty] == 3) { extraPixels = 16899; }
  
  for(int a = 0; a < imageA.pixels.length; a++)
  {
    if(imageA.pixels[a] != imageB.pixels[a])
    {
     offPixels++;
     diff.pixels[a] = color(255,255,255);
    }
    else
     diff.pixels[a] = color(0,0,0);
  }
  diff.save("levels/diff.png");
  print("off pixels " + offPixels + "\n");
  
  if(offPixels < 5000 + extraPixels)
    return true;
  else
    return false;
}

PImage convertToBW(PImage toConvert)
{
 PImage BWImage = createImage(970,600,RGB);
 
 BWImage.loadPixels();
 toConvert.loadPixels();
 
 double arrayLength = toConvert.pixels.length;
 for(int i = 0; i < arrayLength; i++)
 {
   if( red(toConvert.pixels[i]) > 50 || green(toConvert.pixels[i]) > 50 || blue(toConvert.pixels[i]) > 50)
     BWImage.pixels[i] = color(255,255,255);
   else
     BWImage.pixels[i] = color(0,0,0);
 }
 BWImage.updatePixels();
 //BWImage.save("saved_images/outline.png");
 return BWImage;
      
 }
